package net.zdreamer.geracomium.ui.login;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;

import cn.smssdk.SMSSDK;


public class RegistActivity extends RegistBase {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initViews(this);
    }

    /**
     * 申请验证码成功后的操作
     *
     * @param result
     * @param data
     */
    @Override
    protected void afterGet(int result, Object data) {
        if (result == SMSSDK.RESULT_COMPLETE) {
            Message message = myHandler.obtainMessage(GET_SUCCEED);
            message.sendToTarget();
        } else {
            Message message = myHandler.obtainMessage(GET_FAILED);
            message.sendToTarget();
        }
    }


    /**
     * 提交验证码成功后的操作
     *
     * @param result
     * @param data
     */
    @Override
    protected void afterSubmit(int result, Object data) {
        if (SMSSDK.RESULT_COMPLETE == result) {
            Message message = myHandler.obtainMessage(VERIFY_SUCCEED);
            message.sendToTarget();
        } else {
            Message message = myHandler.obtainMessage(VERIFY_FAILED);
            message.sendToTarget();
        }
    }


    Handler myHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case GET_SUCCEED:
                    Toast.makeText(RegistActivity.this, "获取验证码成功", Toast.LENGTH_SHORT).show();
                    realPhoneNum = phoneNum;
                    new MyCount(60000, 1000).start();
                    break;
                case GET_FAILED:
                    Toast.makeText(RegistActivity.this, "获取验证码失败，请检查网络连接或手机号码", Toast.LENGTH_SHORT).show();
                    break;
                case VERIFY_SUCCEED:
                    Toast.makeText(RegistActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
                    RegistActivity.this.finish();
                    break;
                case VERIFY_FAILED:
                    Toast.makeText(RegistActivity.this, "验证码错误", Toast.LENGTH_SHORT).show();
                    break;
            }
        }
    };
}
